home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / swaptp.zip / SWAPDEMO.PAS < prev   
Pascal/Delphi Source File  |  1991-11-06  |  3KB  |  67 lines

  1. {***************************************************************************
  2. *  SWAPDEMO : demonstrates the use of the functions ExecCommand and        *
  3. *             ExecPrg from the SWAP unit                                   *
  4. **------------------------------------------------------------------------**
  5. *  Author           : MICHAEL TISCHER                                      *
  6. *  developed on     : 06/14/1989                                           *
  7. *  last update on   : 03/01/1990                                           *
  8. ***************************************************************************}
  9.  
  10. program SwapDemo;
  11.  
  12. {$M 16384, 0, 655360}                   { allocate all of memory for Turbo }
  13.  
  14. uses Crt, Dos, Swap;                             { include the three units }
  15.  
  16. {***************************************************************************
  17. *                        M A I N  P R O G R A M                            *
  18. ***************************************************************************}
  19.  
  20. var ComSpec : string;                             { command processor path }
  21.     ErrCode : byte;                            { error code of ExecCommand }
  22. begin
  23.   writeln;
  24.   writeln('████████████ SWAPDEMO - (c) 1989 by Michael Tischer ████');
  25.   writeln;
  26.  
  27.   writeln('This is a demonstration of the SWAP unit. Setting the heap');
  28.   writeln('size to 655,360 in the $M compiler directive ensures that');
  29.   writeln('Turbo Pascal allocates all available memory before the');
  30.   writeln('program starts.');
  31.   writeln;
  32.   writeln('On calling the EXEC procedure from Turbo, no other program');
  33.   writeln('can be called, demonstrated by the following test call.');
  34.   writeln;
  35.   write( 'Exec(''\COMMAND.COM'', ''/cdir *.*'') ');
  36.  
  37.   ComSpec := GetEnv( 'COMSPEC' );             { get command processor path }
  38.   Exec( ComSpec, '/cdir *.*' );                        { display directory }
  39.   if ( DosError <> 0 ) then                                      { error ? }
  40.     begin                                               { yes, as expected }
  41.       TextColor( $0 );
  42.       TextBackground( $F );
  43.       write( '<--- Error, no memory!');
  44.       TextColor( $7 );
  45.       TextBackground( $0 );
  46.       writeln;
  47.       writeln;
  48.       writeln('Now the new EXEC COMMAND procedure will execute, which ');
  49.       writeln('places most of the memory on disk or in EMS memory. ');
  50.       writeln;
  51.       writeln( 'ExecCommand( ''dir *.*'' ) ');
  52.  
  53.       ErrCode := ExecCommand( 'dir *.*' );
  54.       writeln;
  55.       if ( ErrCode = SwapErrOk ) then
  56.         writeln('Everything O.K. SwapDemo terminated. ')
  57.       else
  58.         write('Error');
  59.         case ErrCode of                         { read & act on error code }
  60.           SwapErrStore    : writeln(' during memory storage!');
  61.           SwapErrNotFound : writeln(': program not found!');
  62.           SwapErrNoAccess : writeln(': access denied!');
  63.           SwapErrNoRam    : writeln(': program too large!');
  64.        end;
  65.     end;
  66. end.
  67.